//
//  HWBookCell.m
//  嗨文
//
//  Created by 响当当 on 2019/1/9.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookCell.h"

@interface HWBookCell()
@property (nonatomic, strong)UIImageView *bookIconImageView;//书图片
@property (nonatomic, strong)UIImageView *UnReadPointImageView;//书图片
@property (nonatomic, strong)UILabel *bookTitleLabel;//书名
@property (nonatomic, strong)UILabel *bookAuthorAndChapterLabel;//书作者及阅读到哪一章
@property (nonatomic, strong)UILabel *bookUpdateTimeLabel;//书更新时间
@property (nonatomic, strong)UIView *lineView;//下划线

@end

@implementation HWBookCell

- (UIImageView *)bookIconImageView
{
    if (!_bookIconImageView)
    {
        _bookIconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15*kUIScaleBasePlus,8*kUIScaleBasePlus,64*kUIScaleBasePlus,72*kUIScaleBasePlus)];
        _bookIconImageView.image = [UIImage imageNamed:@"bookCommon"];
    }
    return _bookIconImageView;
}

- (UIImageView *)UnReadPointImageView
{
    if (!_UnReadPointImageView)
    {
        _UnReadPointImageView = [[UIImageView alloc] initWithFrame:CGRectMake(12*kUIScaleBasePlus,5*kUIScaleBasePlus,8*kUIScaleBasePlus,8*kUIScaleBasePlus)];
        _UnReadPointImageView.image = [UIImage imageNamed:@"refresh_dot"];
    }
    return _UnReadPointImageView;
}

- (UILabel *)bookTitleLabel
{
    if (!_bookTitleLabel)
    {
        _bookTitleLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookIconImageView.frame)+13*kUIScaleBasePlus,16*kUIScaleBasePlus,SCREEN_WIDTH-83*kUIScaleBasePlus,15*kUIScaleBasePlus)
                                             textAligment:NSTextAlignmentLeft textClor:LCHexColor(0x363636)
                                                 textFont:15*kUIScaleBasePlus];
    }
    return _bookTitleLabel;
}

- (UILabel *)bookAuthorAndChapterLabel
{
    if (!_bookAuthorAndChapterLabel)
    {
        _bookAuthorAndChapterLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookIconImageView.frame)+13*kUIScaleBasePlus,CGRectGetMaxY(self.bookTitleLabel.frame)+11*kUIScaleBasePlus,SCREEN_WIDTH-83*kUIScaleBasePlus,13*kUIScaleBasePlus)
                                                        textAligment:NSTextAlignmentLeft
                                                            textClor:LCHexColor(0x8F8F8F)
                                                            textFont:12*kUIScaleBasePlus];
    }
    return _bookAuthorAndChapterLabel;
}

- (UILabel *)bookUpdateTimeLabel
{
    if (!_bookUpdateTimeLabel)
    {
        _bookUpdateTimeLabel = [HWUtilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.bookIconImageView.frame)+13*kUIScaleBasePlus, CGRectGetMaxY(self.bookAuthorAndChapterLabel.frame)+11*kUIScaleBasePlus,SCREEN_WIDTH-83*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                  textAligment:NSTextAlignmentLeft textClor:LCHexColor(0x8F8F8F) textFont:12*kUIScaleBasePlus];
    }
    return _bookUpdateTimeLabel;
}

- (UIView *)lineView
{
    if (!_lineView)
    {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(80*kUIScaleBasePlus,87*kUIScaleBasePlus,280*kUIScaleBasePlus,1*kUIScaleBasePlus)];
        _lineView.backgroundColor = LCHexColor(0xEBE5E1);
    }
    return _lineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self.contentView addSubview:self.bookIconImageView];
//        [self.contentView addSubview:self.UnReadPointImageView];
        [self.contentView addSubview:self.bookTitleLabel];
        [self.contentView addSubview:self.bookAuthorAndChapterLabel];
        [self.contentView addSubview:self.bookUpdateTimeLabel];
        [self.contentView addSubview:self.lineView];

    }
    return self;
}

#pragma mark - 获取数据
- (void)getBookDetail:(HWBookShelfModel *)model
{
    [self.bookIconImageView sd_setImageWithURL:[NSURL URLWithString:model.bookCover] placeholderImage:[UIImage imageNamed:@"bookCommon"]];
    
    UIColor *bookTitleColor = nil;
    NSString *bookTitleStr = nil;
    if ([model.hasNew boolValue])
    {
        bookTitleColor = LCHexColor(0x49BFA5);
        bookTitleStr = [NSString stringWithFormat:@"%@ %@",model.bookName,@"连载中"];
    }
    else
    {
        bookTitleColor = LCHexColor(0xFF771A);
        bookTitleStr = [NSString stringWithFormat:@"%@ %@",model.bookName,@"已完结"];
    }
    self.bookTitleLabel.attributedText = [bookTitleStr addAttriButedString:bookTitleStr Color:bookTitleColor Font:[UIFont systemFontOfSize:10*kUIScaleBasePlus] rang:NSMakeRange(bookTitleStr.length-3,3)];
    
    
    NSString *bookAuthorAndChapterStr = [NSString stringWithFormat:@"%@ %@",model.authorName,model.readingChapterOrder];
    NSRange range = [bookAuthorAndChapterStr rangeOfString:@" "];
    self.bookAuthorAndChapterLabel.attributedText = [bookAuthorAndChapterStr addAttriButedString:bookAuthorAndChapterStr Color:LCHexColor(0x0A0509) Font:[UIFont systemFontOfSize:13*kUIScaleBasePlus] rang:NSMakeRange(0,range.location)];
    
    
    self.bookUpdateTimeLabel.text = [NSString stringWithFormat:@"%@ %@",model.updateTime,model.lastChapterTitle];
}
@end
